package com.deyang.mycommon.ui.activity.study;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.deyang.mycommon.R;
import com.deyang.mycommon.minterface.RequestPermissionsCallBack;
import com.deyang.mycommon.ui.baseui.BaseActivity;
import com.deyang.mycommon.ui.activity.basics.SelectImagesActivity;
import com.deyang.mycommon.util.PermissionUtil;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.OnClick;
import pub.devrel.easypermissions.EasyPermissions;


public class MainActivity extends BaseActivity implements View.OnClickListener, EasyPermissions.PermissionCallbacks {

    private static final String TAG = "MainActivity";

    public final static String[] PERMS_WRITE = {
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.RECORD_AUDIO,
    };

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }


    @OnClick({
            R.id.btn1,
            R.id.btn2,
            R.id.btn3,
            R.id.btn4,
            R.id.btn_openPdf,
            R.id.btn_detailPlayer,
    })
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn1:
                boolean hasPermission = PermissionUtil.isHasPermission(this, PERMS_WRITE);
                showToastInfo(hasPermission + "");
                if (!hasPermission) {
                    requestPermissions(this, "我要获取存储权限", "存储或音频", 0x001, new RequestPermissionsCallBack() {
                        @Override
                        public void onPermissionsGranted(List<String> perms) {
                            StringBuilder sb = new StringBuilder();
                            for (String per : perms) {
                                sb.append(per + "\n\n");
                            }
                            Toast.makeText(MainActivity.this, "权限申请成功" + sb.toString(), Toast.LENGTH_SHORT).show();
                        }
                    }, PERMS_WRITE);
                }
                break;
            case R.id.btn2:
                startActivity(new Intent(this, SelectImagesActivity.class));
                break;
            case R.id.btn3:
                startActivity(new Intent(this, BaseAdapterActivity.class));
                break;
            case R.id.btn4:
                startActivity(new Intent(this, PhoneAddressSeachActivity.class));
                break;
            case R.id.btn_openPdf:
                startActivity(new Intent(this, PDFViewActivity.class));
                break;
            case R.id.btn_detailPlayer:
                startActivity(new Intent(this, PlayerDetailActivity.class));
                break;
        }
    }


}
